<?php 
class Login_Model extends Model
{ 
	var $table = 'admin_login_info'; 
	var $login_id = ''; 
	function Login_Model()
	{ 
		parent::Model();
	}
	function authenticate($table , $array)
	{ 
		$this->db->select("*");
		$this->db->from($table);
		$this->db->where($array);
		$query = $this->db->get(); 
		$row =	$query->row(); 
		$this->login_id = $row->id;
		return  $query; 
		
	} 
	function update_verification_code($table,$condition )
	{ 
		$vCode = time().rand(1111,999999); 
		$data = array('verification_code' => $vCode);
		$this->db->where($condition);
		$this->db->update($table, $data); 
		return $vCode; 
	} 
	function check_verification_code($table , $condition)
	{ 
		$this->db->where($condition);
		$query = $this->db->get($table); 
		if($query->num_rows()==1)
			return true;  
		else 
			return false; 
	} 
	function check_email($table,$array)
	{ 
		$this->db->select( '*' );
		$this->db->where( $array ); 
		$query =  $this->db->get( $table );
		if ( $query->num_rows() == 1 ) 
		return $query->row(); 
		else 
		return false; 
	} 
	
	function admin_info($table , $field=NULL)
	{ 
		$this->db->select('*');
		$this->where('id', $this->login_id ); 
		$query =  $this->db->get($table);
		if (is_null($field)) 
		return $query->row(); 
		else 
		return $query->row()->$field; 
	} 
	
	function change_password($table,$new_password,$condition) 
	{ 
		$data = array('password' =>$new_password );
		$this->db->where($condition);
		if ($this->db->update($table, $data)) 
			return true; 
		else 
			return false; 
	}


	function empty_verification_code( $table,$condition )
	{ 
		$data = array('verification_code' => NULL);
		$this->db->where($condition);
		$this->db->update($table, $data); 
	}      	
	
	function is_valid_team($team_id)
	{
		$this->db->where('id', $team_id);
		$this->db->from('tbl_team_info');
		if($this->db->count_all_results() == 1)
			return true;
		else
			return false;
	}
	
	function get_team_login_info($team_id)
	{
		$this->db->select('*');
		$this->db->where('team_id', $team_id);
		$this->db->where('type', 'coach');
		$this->db->where('status', 'active');
		$query = $this->db->get('tbl_team_members_info');
		return $query->row();
	}
	
	function get_time_offset($member_id)
	{
		$this->db->select('time_offset');
		$this->db->from('view_park_leauge_team_member');
		$this->db->join('tbl_states', 'view_park_leauge_team_member.state_id = tbl_states.state_id');
		$this->db->where('member_id', $member_id);
		$query = $this->db->get();
		$result = $query->row();
		return $result->time_offset;
	}
		
} 
 
